<table id="RO" class="easyui-datagrid" title="Aktifasi SN" style="height:500px"
                data-options="
                        url: '<?php echo $this->baseUrl() ?>/jsondata/getsn',
                        fitColumns: true,
                        singleSelect: true,
                        rownumbers: true,
                        showFooter: true,
                        rownumbers: true,
                        autoRowHeight:false,
                        checkbox: true,
                        singleSelect:false,
                        checkOnSelect: true,
                        pagination:true,
                        pageSize:10,
                        toolbar:'#tb'
                ">
        <thead>
                <tr>
                        <th data-options="field:'ck',checkbox:true"></th>
                        <th data-options="field:'serial_number',width:80">SN</th>
                        <th data-options="field:'status',width:140">Status</th>
                </tr>
        </thead>
    </table>

<div class="content-inner">
        <input type="button" class="bttn" value="Aktifkan yang dipilih" onclick="return submitSN('1')" />
        <input type="button" class="bttn" value="Aktifkan semua" onclick="return submitSN('2')" />
        <input type="button" class="bttn" value="Pasifkan semua" onclick="return submitSN('3')" />

        <!--a href="#" class="easyui-linkbutton" onclick="return submitRO('T')">Set Repeat Order</a>
        <a href="#" class="easyui-linkbutton" onclick="return submitRO('F')">Unset Repeat Order</a-->

</div>


<div id="tb" style="padding:5px;height:auto">
        <div class="content-inner">
        <form id="frmRO" method="post" enctype="application/x-www-form-urlencoded">
        <table>
                <tr>
                        <td>SN</td>
                        <td>:</td>
                        <td>
                            <input class="easyui-validatebox" type="text" style="width:150px" name="sn" id="sn" value="<?php echo (isset($this->data['sn'])) ? $this->data['sn'] : ""; ?>"></input>
                            <input type="hidden" name="snList" id="snList">
                            <input type="hidden" name="flag" id="flag">
                        </td>
                        
                </tr>
                <tr>
                        <td>Status</td>
                        <td>:</td>
                        <td>
                            <select name="stts" id="stts">
                                <option value="">Semua Status</option>
                                <option value="-1">Pasif/Tidak Aktif</option>
                                <option value="0">Aktif</option>
                                <option value="1">Sudah Digunakan</option>
                            </select>
                            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search"  onclick="getData()">Cari</a>
                        </td>

                </tr>
        </table>
    </form>
            <?php
        //if ($this->errorMsg == "" && $this->id == "") echo "<br>";

        if ($this->errorMsg != ""){
            echo '<div class="msg-info">
		<div class="msg-tip icon-tip"></div>
		<div>'. $this->errorMsg .'</div>
            </div>';
        }

        if ($this->id != ""){
            echo '<div class="msg-info">
		<div class="msg-tip icon-ok"></div>
		<div>'. $this->id .'</div>
            </div>';
        }
        ?>
    </div>
</div>

<script>
        
        function cek(flag){
            var msg = [];

            //var xx = $('#RO').datagrid('getData');
            //alert(xx.length);


            var rows = $('#RO').datagrid('getSelections');
            
            if (rows.length == 0 && flag == 1) msg.push('<span>* SN harus dipilih</span>');
            if (msg.length == 0) return true;
            else{
                //alert("Data tidak lengkap:\n\n" + msg);
                //$.messager.alert("Data tidak lengkap:\n\n" + msg);
                $.messager.alert('Info', msg.join('<br/>'));
                return false;
            }
        }

        function submitSN(flag){
                if (cek(flag)){
                    var ss = [];
                    var rows = $('#RO').datagrid('getSelections');
                    for(var i=0; i<rows.length; i++){
                            var row = rows[i];
                            //ss.push('<span>'+row.trans_dtm+":"+row.productid+":"+row.attr1+'</span>');
                            ss.push("'"+row.serial_number+"'");
                    }

                    var dataSN = ss.join(',');
                    
                    $('#snList').val(dataSN);
                    $('#flag').val(flag);
                    //$.messager.alert('Info', ss.join(','));

                    $('#frmRO').submit();
               }
        }


        function getData(){

            var sn = $('#sn').val();
            var stts = $('#stts').val();


            $('#RO').datagrid({
                queryParams: {
                page: 1,
                rows: 10,
                sn: sn,
                stts: stts
                }
                });



    }
</script>




